import time
# 导入显示等待的包
from selenium.webdriver.support.ui import WebDriverWait
# 导入隐式等待的包
from selenium.webdriver.support import expected_conditions as EC
# 导入鼠标事件的包
from selenium.webdriver.common.action_chains import ActionChains
# 导入Select选择器
from selenium.webdriver.support.select import Select
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

driver = webdriver.Edge()
# 浏览器事件获取网址
driver.get('https://www.douban.com')
# 浏览器事件窗口最大化
driver.maximize_window()
# 强制等待
time.sleep(3)
# 进入frame框架
f = driver.find_element(By.XPATH, '//*[@id="anony-reg-new"]/div/div[1]/iframe')
driver.switch_to.frame(f)
time.sleep(2)
# 第一步 点击密码登录
shuru = driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/ul[1]/li[2]')
shuru.click()
time.sleep(2)
# 文本值
print(shuru.text)
# 获取元素的具体属性值（比如class）
print(shuru.get_attribute('class'))
# 获取元素的宽高
print(shuru.size)
# 获取元素的坐标值
print(shuru.location)
# 打印元素是否可用
print(shuru.is_displayed())
# 打印元素是否显示
print(shuru.is_displayed())
# 打印元素是否被选中
print(shuru.is_selected())
# 第二步 输入账号
driver.find_element(By.ID, 'username').send_keys('18185603008')
driver.implicitly_wait(2)
# 第三步 点输入密码
driver.find_element(By.ID, 'password').send_keys('123456Aa')
time.sleep(2)

# time.sleep(25)
# 第四步 点击登录
# 显示等待
# dl = WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR, '.btn.btn-phone')))
dl = driver.find_element(By.XPATH,'/html/body/div[1]/div[2]/div[1]/div[5]/a').click()
time.sleep(3)
# # 第五步 输入aaa
shuru2 = driver.find_element(By.XPATH, '//*[@id="pt"]/div/div/div[1]/div/div/div[1]t')
shuru.send_keys('aaaaa')
time.sleep(2)
# 键盘全选事件
shuru.send_keys(Keys.CONTROL,'a')
time.sleep(2)
# 键盘剪切事件
shuru.send_keys(Keys.CONTROL,'x')
time.sleep(2)
# 键盘复制事件
shuru.send_keys(Keys.CONTROL,'c')
time.sleep(2)
# # 鼠标悬停事件
ActionChains(driver).move_to_element(shuru).perform()
time.sleep(2)
# 鼠标单击事件
ActionChains(driver).context_click(shuru).perform()
time.sleep(2)
# 鼠标双击事件
ActionChains(driver).double_click(shuru).perform()
time.sleep(2)
# XPATH逻辑定位
driver.find_element(By.XPATH,'//input[@id="inp-query" and name="q"]')
time.sleep(2)
xzq = Select(driver.find_element(By.ID,'inp-query'))
# index
xzq.select_by_index(1)
# value
xzq.select_by_value('32')
# text
xzq.select_by_visible_text('南京')
alert = driver.switch_to.alert
alert.accept()




